﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace SYH.Public.BLL
{
    public class PublicAlbum
    {
        private static readonly SYH.Public.DAL.PublicAlbum dal = new DAL.PublicAlbum();

        #region 根据相册名称判断是否存在
        /// <summary>
        /// 根据相册名称判断是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static int GetNameExist(string name, int UserId)
        {
            return dal.GetNameExist(name, UserId);
        }
        #endregion

        #region 增加相册
        /// <summary>
        /// 增加相册
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Add(Model.PublicAlbum model)
        {
            return dal.Add(model);
        }
        #endregion

        #region 删
        /// <summary>
        /// 删除相册，真删 若相册有图片则删除失败
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static bool Delete(int Id, int UserId)
        {
            return dal.Delete(Id, UserId);
        }
        #endregion

        #region 根据id倒序分页
        /// <summary>
        /// 根据id倒序分页
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageCount"></param>
        /// <param name="recordCount"></param>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static DataSet PageOrderByIdDesc(int pageSize, int pageIndex, out int pageCount, out int recordCount, int UserId)
        {
            return Common.PublicSqlData.SimplePager(Config.WebConfig.SqlConnString, "Public_Album", "Id,ImgCount,FrontCover,Name,CreateTime", pageSize, pageIndex, "Id", true, " And UserId=" + UserId, out pageCount, out recordCount);
        }
        #endregion

        #region 查
        /// <summary>
        /// GetModel
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public static Model.PublicAlbum GetModel(int Id)
        {
            return dal.GetModel(Id);
        }
        #endregion

        #region 改
        /// <summary>
        /// 相册重命名
        /// </summary>
        /// <param name="Id">相册Id</param>
        /// <param name="Name">新名字</param>
        /// <returns></returns>
        public static bool UpdateName(int Id, string Name)
        {
            return dal.UpdateOneField("Name", Name, " Id=" + Id, true);
        }
        #endregion

        #region 设置相册封面
        /// <summary>
        /// 设置相册封面
        /// </summary>
        /// <param name="albumId">相册编号</param>
        /// <param name="imageName">图片名</param>
        public static void SetCoverFile(int albumId, string imageName)
        {
            dal.UpdateOneField("[FrontCover]", imageName, "Id=" + albumId, true);
        }
        #endregion

        #region 查找会员相册，若未找到将创建“我的相册”，返回0说明当前会员已创建过相册
        /// <summary>
        /// 查找会员相册，若未找到将创建“我的相册”，返回0说明当前会员已创建过相册
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static int ExistsOrAdd(int UserId)
        {
            return dal.ExistsOrAdd(UserId);
        }
        #endregion

        #region 获取会员相册列表
        /// <summary>
        /// 获取会员相册列表
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        public static IList<Model.PublicAlbum> GetModelList(int UserId)
        {
            return dal.GetModelList(UserId);
        }
        #endregion

        #region 相册权限
        /// <summary>
        /// 相册权限
        /// </summary>
        /// <param name="Id">相册Id</param>
        /// <param name="Name">新名字</param>
        /// <returns></returns>
        public static bool UpdateIsShow(int Id, int value)
        {
            return dal.UpdateOneField("IsShow", value.ToString(), " Id=" + Id, false);
        }
        #endregion
    }
}
